
package cn.bluethink.eguan.model.okrtask;

import java.util.Date;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonInclude;

import cn.bluethink.eguan.model.core.EgOType;
import cn.bluethink.eguan.model.core.EgObject;
import cn.bluethink.eguan.model.core.EgTask;
import cn.bluethink.eguan.model.core.EgUser;
import cn.bluethink.eguan.utils.OkrTaskUtil;

/**
 * @title 日常工作和培训任务
 * @Copyright 苏州中科蓝迪公司所有(c)2016-2021
 * @version 0.1
 *
 * @note 修订历史： （1）liuxn于2018年8月14日构建初始版本0.1
 *       （2）giszyj@126.com于2018年10月06日增加timing和btrain属性 增加任务的关键结果列表
 */
public class EgOkrTask extends EgTask {

    /**
     * 默认的颜色列表 
     * 0xf9dc84, 0x84f1f9, 0xd8f984, 0xf26a7a 
     */
    private static int[] defaultColors = { 0xf5cb4a, 0x22c8d5, 0xa5dd18, 0xf26a7a };

    /**
     * 用于显示的标记，不需要持久化
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String label = null;

    /**
     * 评价
     */
    private String evaluate;

    /**
     * 任务计时类型（日、周、月、季度、年）
     */
    private Integer timing;

    /**
     * 做任务奖励的经验值/技能点
     */
    private Integer expSkp;

    /**
     * 做任务的人
     */
    private EgUser douser;

    /**
     * 做完任务提交的结果
     */
    private EgObject result;

    /**
     * 如果该工作任务为目标，该字段为当前目标的前置目标
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private EgOkrTask parent;

    /**
     * 目标颜色，如果有目标标签，该项有对应显示
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Integer color = null;

    /**
     * 任务关键项列表
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private List<EgTaskKR> taskkrList = null;

    /**
     * @since 1.0.0
     * @roseuid 5B6D4F61009E
     */
    public EgOkrTask() {
        setType(new EgOType(EgOType.OKR_TASK, null));
    }

    public EgOkrTask(Long tid, String name, String content) {
        super(tid, name, content, new EgOType(EgOType.OKR_TASK, null));
    }

    public String getLabel() {
        return label;
    }

    /**
     * 计算标签label
     * 
     * @param bmonth
     * @throws Exception
     */
    public void calculateLabel(Integer bmonth) {
        Date etime = getEtime();
        if (timing == null || etime == null) {
            return;
        }
        OkrTaskUtil util = new OkrTaskUtil();
        label = util.label(timing, etime, bmonth);
    }

    public Integer getTiming() {
        return timing;
    }

    public void setTiming(Integer timing) {
        if (timing == null || timing < EgTimingType.WEEK_TARGET)
            return;
        else if (color == null)// && timing >= EgTimingType.WEEK_TARGET && timing <= EgTimingType.YEAR_TARGET)
            color = defaultColors[timing - 1];
        this.timing = timing;
    }

    public Integer getExpSkp() {
        return expSkp;
    }

    public void setExpSkp(Integer expSkp) {
        this.expSkp = expSkp;
    }

    public EgUser getDouser() {
        return douser;
    }

    public void setDouser(EgUser douser) {
        this.douser = douser;
    }

    public EgObject getResult() {
        return result;
    }

    public void setResult(EgObject result) {
        this.result = result;
    }

    public List<EgTaskKR> getTaskkrList() {
        return taskkrList;
    }

    public void setTaskkrList(List<EgTaskKR> taskkrList) {
        this.taskkrList = taskkrList;
    }

    public String getEvaluate() {
        return evaluate;
    }

    public void setEvaluate(String evaluate) {
        this.evaluate = evaluate;
    }

    public EgOkrTask getParent() {
        return parent;
    }

    public void setParent(EgOkrTask parent) {
        this.parent = parent;
    }

    public Integer getColor() {
        return color;
    }

    public void setColor(Integer color) {
        this.color = color;
    }

}
